package com.hdu.heihei.beans;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author fengyuan
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class User
{
    int id;
    String username;
    String password;

    /**
     * 自定义排序
     * @param userList
     */
    public void sortById(List<User> userList) {
        Collections.sort(userList, new Comparator<User>() {
            @Override
            public int compare(User u1, User u2) {
                if (u1.getId() > u2.getId()) {
                    return -1;
                } else if (u1.getId() < u2.getId()) {
                    return 1;
                } else {//相等
                    return 0;
                }

            }
        });
    }


}

//对对象的一些操作